package com.sx.pipeline.ui.task.add

import android.Manifest
import android.graphics.BitmapFactory
import android.net.Uri
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.PermissionUtils
import com.blankj.utilcode.util.ToastUtils
import com.loper7.date_time_picker.DateTimeConfig
import com.loper7.date_time_picker.dialog.CardDatePickerDialog
import com.luck.picture.lib.basic.PictureSelector
import com.luck.picture.lib.config.SelectMimeType
import com.luck.picture.lib.entity.LocalMedia
import com.luck.picture.lib.interfaces.OnResultCallbackListener
import com.lxj.xpopup.XPopup
import com.permissionx.guolindev.PermissionX
import com.sx.mvvmlibs.base.EasyAdapter
import com.sx.mvvmlibs.utils.Logs
import com.sx.mvvmlibs.view.SpaceItemDecoration
import com.sx.pipeline.BR
import com.sx.pipeline.R
import com.sx.pipeline.adapter.ReleaseTypeAdapter
import com.sx.pipeline.app.base.CYDataBindingBaseActivity
import com.sx.pipeline.arouth.RouteManager
import com.sx.pipeline.arouth.RoutePath
import com.sx.pipeline.custom.dialog.CustomCommonPicket
import com.sx.pipeline.databinding.ActReleaseAddBinding
import com.sx.pipeline.repos.http.res.RongGroupVO
import com.sx.pipeline.repos.http.res.TaskConfig
import com.sx.pipeline.ui.task.ReleaseTaskVM
import com.sx.pipeline.utils.AndroidUtil
import com.sx.pipeline.utils.CompressHelper
import com.sx.pipeline.utils.GlideEngine
import com.sx.pipeline.utils.PermissionHelper
import io.rong.imkit.RongIM


/**
 * @Author: YY
 * @Date: 2022/4/5
 * @Description: 发布任务
 */
@Route(path = RoutePath.Mine.RELEASE_TASK_ADD)
class ReleaseTaskAddActivity :
    CYDataBindingBaseActivity<ActReleaseAddBinding, ReleaseTaskVM>(R.layout.act_release_add),
    View.OnClickListener {
    private var mAdapter: ReleaseTypeAdapter? = null
    private var mAdapterCondition: ReleaseTypeAdapter? = null
//    private var mAdapterDisclosure: DisclosureTypeAdapter? = null //交底单位类型适配器

    private var longitude: String = "" //经度
    private var latitude: String = "" //纬度
    private var addressDetail: String = "" //详细地址
    private var startTime: String = "" //开始时间
    private var endTime: String = "" //结束时间
    private var taskTypeList: MutableList<String> = ArrayList() //任务类型集合
    private var taskConditionList: MutableList<String> = ArrayList() //任务发布现场类型集合

    private var uploadType: Int = 1; //1 上传现场勘查图片 2 施工图纸 3 市政审批手续


    override fun onStart() {
        super.onStart()

    }

    override fun initData() {
        mBinding.setVariable(BR.onClick, this)
        mBinding.titleBar.leftView.setOnClickListener {
            finish()
        }
        //获取当前登录单位信息
        mViewModel.getUserUnit()
        //请求添加任务数据选择列表
        mViewModel.getTask()
        //请求负责人列表
        mViewModel.getContacts()
        //默认回填手机号
        mBinding.etPrincipalPhone.setText(mViewModel.mModel.getUserData()?.phone)
        mBinding.etPrincipal.setText(mViewModel.mModel.getUserData()?.userName)

        initExplorationPhotosn()
        initConstructionDrawings()
        initApprovalProcedures()
    }

    override fun initViewObservable() {
        super.initViewObservable()
        observe(mViewModel.taskListEvent) {
            //初始化任务类型
            it?.TASK_TYPE?.let { it1 -> initTaskType(it1) }
            //初始化现场勘探情况类表
            it?.LIVE_SITUATION?.let { it1 -> initTaskCondition(it1) }
        }

        observe(mViewModel.locationEvent) {
            longitude = it?.latLonPoint?.longitude.toString()
            latitude = it?.latLonPoint?.latitude.toString()
            addressDetail = it?.snippet.toString()
            mBinding.sbLocation.rightText = "${it?.title.toString()} ${it?.snippet.toString()}"
        }

        //图片上传结果
        observe(mViewModel.uploadDataEvent) {
            when (uploadType) {
                1 -> mBinding.imageUploadExplorationPhotos.addImage(it)
                2 -> mBinding.imageUploadConstructionDrawings.addImage(it)
                3 -> mBinding.imageUploadApprovalProcedures.addImage(it)
            }
        }

        //加载当前发布单位
        observe(mViewModel.userUnitEvent) {
            mBinding.sbUnit.rightText = it?.name
        }

        observe(mViewModel.successTaskEvent) {
            if (it == true) {

            }
        }

        //审批成功 提示创建群聊
        observe(mViewModel.auditGroupSuccessEvent) {
//            if (it?.userUnitIds?.size == 0 || it?.userUnitIds==null) {
//                ARouter.getInstance().build(RoutePath.Mine.RELEASE_RESULT).navigation()
//                finish()
//                return@observe
//            }
            XPopup.Builder(
                this
            ) //                        .hasNavigationBar(false)
                //                        .hasStatusBar(false)
                .isDestroyOnDismiss(true) //                        .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                //                        .isViewMode(true)
                //                        .hasBlurBg(true)
                //                         .autoDismiss(false)
                //                        .popupAnimation(PopupAnimation.NoAnimation)
                .asConfirm(getString(R.string.hint),
                    getString(R.string.q_task_success_create_group),
                    getString(R.string.cancel),
                    getString(R.string.confirm),
                    {
                        it?.orderId?.let { it1 ->
                            mViewModel.getTaskCreateGroup(
                                1, mBinding.etName.text.toString(),
                                it1
                            )
                        }
                    },
                    {
                        ARouter.getInstance().build(RoutePath.Mine.RELEASE_RESULT).navigation()
                        finish()
                    },
                    false
                ).show()
        }

        //群聊创建成功
        observe(mViewModel.groupSuccessEvent) {
            if (it == true) {
                mViewModel.getRongGroupList()
            }
        }


        observe(mViewModel.groupListEvent) {
            if (it != null) {
                refreshRongGroupInfo(it)
            }
        }
    }

    //任务类型
    private fun initTaskType(data: List<TaskConfig>) {
        mAdapter = ReleaseTypeAdapter(this, data)
        mBinding.rvTaskType.layoutManager =
            GridLayoutManager(this, 3)
        mBinding.rvTaskType.addItemDecoration(
            SpaceItemDecoration(15)
        )
        mBinding.rvTaskType.adapter = mAdapter
        mAdapter?.selectMode = EasyAdapter.SelectMode.MULTI_SELECT
    }

    private fun initTaskCondition(data: List<TaskConfig>) {
        mAdapterCondition = ReleaseTypeAdapter(this, data)
        mBinding.rvPreliminarySurvey.layoutManager =
            GridLayoutManager(this, 3)
        mBinding.rvPreliminarySurvey.addItemDecoration(
            SpaceItemDecoration(15)
        )
        mBinding.rvPreliminarySurvey.setAdapter(mAdapterCondition)
        mAdapterCondition?.setSelectMode(EasyAdapter.SelectMode.MULTI_SELECT)
    }

    //施工现场勘查
    private fun initExplorationPhotosn() {
        // 上传图片
        mBinding.imageUploadExplorationPhotos.initAdapter(3, 3)
        mBinding.imageUploadExplorationPhotos.setImageUploadListener {
            uploadType = 1
            PermissionHelper.requestTip(this,"上次图片需要授权相机和读写权限",object :
                PermissionUtils.SimpleCallback{
                override fun onGranted() {
                    PictureSelector.create(this@ReleaseTaskAddActivity)
                        .openGallery(SelectMimeType.ofImage())
                        .setImageEngine(GlideEngine.createGlideEngine())
                        .setMaxSelectNum(3 - mBinding.imageUploadExplorationPhotos.imagePath.size)
                        .forResult(object : OnResultCallbackListener<LocalMedia?> {
                            override fun onResult(result: ArrayList<LocalMedia?>?) {
                                //循环上传图片
                                for (i in 0 until result?.size!!) {
                                    Log.d("okhttp", "" + result[i]?.realPath)
                                    //压缩图片
                                    val inputBitmap =
                                        BitmapFactory.decodeFile(result[i]?.realPath)
                                    val compressFile = CompressHelper.compressQuality(
                                        this@ReleaseTaskAddActivity, inputBitmap
                                    )
                                    mViewModel.uploadImage(compressFile)
                                }
                            }

                            override fun onCancel() {}
                        })
                }

                override fun onDenied() {
                    ToastUtils.showShort("请授权后再继续操作")
                }
            },Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.CAMERA)

//            PermissionX.init(this)
//                .permissions(
//                    Manifest.permission.READ_EXTERNAL_STORAGE,
//                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
//                    Manifest.permission.CAMERA
//                )
//                .onExplainRequestReason { scope, deniedList ->
//                    scope.showRequestReasonDialog(
//                        deniedList,
//                        "核心基础功能基于这些权限,请允许,否则影响app正常使用",
//                        "确认",
//                        "取消"
//                    )
//                }
//                .onForwardToSettings { scope, deniedList ->
//                    scope.showForwardToSettingsDialog(
//                        deniedList,
//                        "您需要手动在“设置”中允许必要的权限",
//                        "确定",
//                        "取消"
//                    )
//                }
//                .request { allGranted, grantedList, deniedList ->
//                    if (allGranted) {
//                        PictureSelector.create(this)
//                            .openGallery(SelectMimeType.ofImage())
//                            .setImageEngine(GlideEngine.createGlideEngine())
//                            .setMaxSelectNum(3 - mBinding.imageUploadExplorationPhotos.imagePath.size)
//                            .forResult(object : OnResultCallbackListener<LocalMedia?> {
//                                override fun onResult(result: ArrayList<LocalMedia?>?) {
//                                    //循环上传图片
//                                    for (i in 0 until result?.size!!) {
//                                        Log.d("okhttp", "" + result[i]?.realPath)
//                                        //压缩图片
//                                        val inputBitmap =
//                                            BitmapFactory.decodeFile(result[i]?.realPath)
//                                        val compressFile = CompressHelper.compressQuality(
//                                            this@ReleaseTaskAddActivity, inputBitmap
//                                        )
//                                        mViewModel.uploadImage(compressFile)
//                                    }
//                                }
//
//                                override fun onCancel() {}
//                            })
//                    } else {
//                        ToastUtils.showShort(getString(R.string.txt_these_permissions_are_denied))
//                    }
//                }

        }
    }

    //施工图纸
    private fun initConstructionDrawings() {
        // 上传图片
        mBinding.imageUploadConstructionDrawings.initAdapter(3, 3)
        mBinding.imageUploadConstructionDrawings.setImageUploadListener {
            uploadType = 2
            PermissionHelper.requestTip(this,"上次图片需要授权相机和读写权限",object :
                PermissionUtils.SimpleCallback{
                override fun onGranted() {
                    PictureSelector.create(this@ReleaseTaskAddActivity)
                        .openGallery(SelectMimeType.ofImage())
                        .setImageEngine(GlideEngine.createGlideEngine())
                        .setMaxSelectNum(3 - mBinding.imageUploadConstructionDrawings.imagePath.size)
                        .forResult(object : OnResultCallbackListener<LocalMedia?> {
                            override fun onResult(result: ArrayList<LocalMedia?>?) {
                                //循环上传图片
                                for (i in 0 until result?.size!!) {
                                    Log.d("okhttp", "" + result[i]?.realPath)
                                    //压缩图片
                                    val inputBitmap =
                                        BitmapFactory.decodeFile(result[i]?.realPath)
                                    val compressFile = CompressHelper.compressQuality(
                                        this@ReleaseTaskAddActivity,
                                        inputBitmap
                                    )
                                    mViewModel.uploadImage(compressFile)
                                }
                            }

                            override fun onCancel() {}
                        })
                }

                override fun onDenied() {
                    ToastUtils.showShort("请授权后再继续操作")
                }
            },Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.CAMERA)

//            PermissionX.init(this)
//                .permissions(
//                    Manifest.permission.READ_EXTERNAL_STORAGE,
//                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
//                    Manifest.permission.CAMERA
//                )
//                .onExplainRequestReason { scope, deniedList ->
//                    scope.showRequestReasonDialog(
//                        deniedList,
//                        "核心基础功能基于这些权限,请允许,否则影响app正常使用",
//                        "确认",
//                        "取消"
//                    )
//                }
//                .onForwardToSettings { scope, deniedList ->
//                    scope.showForwardToSettingsDialog(
//                        deniedList,
//                        "您需要手动在“设置”中允许必要的权限",
//                        "确定",
//                        "取消"
//                    )
//                }
//                .request { allGranted, grantedList, deniedList ->
//                    if (allGranted) {
//                        PictureSelector.create(this)
//                            .openGallery(SelectMimeType.ofImage())
//                            .setImageEngine(GlideEngine.createGlideEngine())
//                            .setMaxSelectNum(3 - mBinding.imageUploadConstructionDrawings.imagePath.size)
//                            .forResult(object : OnResultCallbackListener<LocalMedia?> {
//                                override fun onResult(result: ArrayList<LocalMedia?>?) {
//                                    //循环上传图片
//                                    for (i in 0 until result?.size!!) {
//                                        Log.d("okhttp", "" + result[i]?.realPath)
//                                        //压缩图片
//                                        val inputBitmap =
//                                            BitmapFactory.decodeFile(result[i]?.realPath)
//                                        val compressFile = CompressHelper.compressQuality(
//                                            this@ReleaseTaskAddActivity,
//                                            inputBitmap
//                                        )
//                                        mViewModel.uploadImage(compressFile)
//                                    }
//                                }
//
//                                override fun onCancel() {}
//                            })
//                    } else {
//                        ToastUtils.showShort(getString(R.string.txt_these_permissions_are_denied))
//                    }
//                }

        }
    }

    //市政审批手续
    private fun initApprovalProcedures() {
        // 上传图片
        mBinding.imageUploadApprovalProcedures.initAdapter(3, 3)
        mBinding.imageUploadApprovalProcedures.setImageUploadListener {
            uploadType = 3
            PermissionHelper.requestTip(this,"上次图片需要授权相机和读写权限",object :
                PermissionUtils.SimpleCallback{
                override fun onGranted() {
                    PictureSelector.create(this@ReleaseTaskAddActivity)
                        .openGallery(SelectMimeType.ofImage())
                        .setImageEngine(GlideEngine.createGlideEngine())
                        .setMaxSelectNum(3 - mBinding.imageUploadApprovalProcedures.imagePath.size)
                        .forResult(object : OnResultCallbackListener<LocalMedia?> {
                            override fun onResult(result: ArrayList<LocalMedia?>?) {
                                //循环上传图片
                                for (i in 0 until result?.size!!) {
                                    Log.d("okhttp", "" + result[i]?.realPath)
                                    //压缩图片
                                    val inputBitmap =
                                        BitmapFactory.decodeFile(result[i]?.realPath)
                                    val compressFile = CompressHelper.compressQuality(
                                        this@ReleaseTaskAddActivity,
                                        inputBitmap
                                    )
                                    mViewModel.uploadImage(compressFile)
                                }
                            }

                            override fun onCancel() {}
                        })

                }

                override fun onDenied() {
                    ToastUtils.showShort("请授权后再继续操作")
                }
            },Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.CAMERA)

//            PermissionX.init(this)
//                .permissions(
//                    Manifest.permission.READ_EXTERNAL_STORAGE,
//                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
//                    Manifest.permission.CAMERA
//                )
//                .onExplainRequestReason { scope, deniedList ->
//                    scope.showRequestReasonDialog(
//                        deniedList,
//                        "核心基础功能基于这些权限,请允许,否则影响app正常使用",
//                        "确认",
//                        "取消"
//                    )
//                }
//                .onForwardToSettings { scope, deniedList ->
//                    scope.showForwardToSettingsDialog(
//                        deniedList,
//                        "您需要手动在“设置”中允许必要的权限",
//                        "确定",
//                        "取消"
//                    )
//                }
//                .request { allGranted, grantedList, deniedList ->
//                    if (allGranted) {
//                        PictureSelector.create(this)
//                            .openGallery(SelectMimeType.ofImage())
//                            .setImageEngine(GlideEngine.createGlideEngine())
//                            .setMaxSelectNum(3 - mBinding.imageUploadApprovalProcedures.imagePath.size)
//                            .forResult(object : OnResultCallbackListener<LocalMedia?> {
//                                override fun onResult(result: ArrayList<LocalMedia?>?) {
//                                    //循环上传图片
//                                    for (i in 0 until result?.size!!) {
//                                        Log.d("okhttp", "" + result[i]?.realPath)
//                                        //压缩图片
//                                        val inputBitmap =
//                                            BitmapFactory.decodeFile(result[i]?.realPath)
//                                        val compressFile = CompressHelper.compressQuality(
//                                            this@ReleaseTaskAddActivity,
//                                            inputBitmap
//                                        )
//                                        mViewModel.uploadImage(compressFile)
//                                    }
//                                }
//
//                                override fun onCancel() {}
//                            })
//                    } else {
//                        ToastUtils.showShort(getString(R.string.txt_these_permissions_are_denied))
//                    }
//                }

        }
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            //选择标题
            R.id.sb_title -> {
                if (mViewModel.taskTitleData.size == 0) {
                    ToastUtils.showShort("未获取到数据")
                    return
                }
                val popup = CustomCommonPicket(this, getString(R.string.txt_choose_task_title))
                popup.setPickerData(mViewModel.taskTitleData)
                popup.setCommonPickerListener { _, data ->
                    mBinding.sbTitle.rightText = data
                }
                XPopup.Builder(this)
                    .borderRadius(42f)
                    .isDarkTheme(false)
                    .asCustom(popup)
                    .show()
            }
            //选择计量单位
            R.id.sb_measurement_unit -> {
                if (mViewModel.taskUnitData.size == 0) {
                    ToastUtils.showShort("未获取到数据")
                    return
                }
                val popup =
                    CustomCommonPicket(this, getString(R.string.txt_choose_measurement_unit))
                popup.setPickerData(mViewModel.taskUnitData)
                popup.setCommonPickerListener { _, data ->
                    mBinding.sbMeasurementUnit.rightText = data
                }
                XPopup.Builder(this)
                    .borderRadius(42f)
                    .isDarkTheme(false)
                    .asCustom(popup)
                    .show()
            }
            //选择任务性质
            R.id.sb_nature_task -> {
                if (mViewModel.taskNatureData.size == 0) {
                    ToastUtils.showShort("未获取到数据")
                    return
                }
                val popup = CustomCommonPicket(this, getString(R.string.txt_choose_nature_task))
                popup.setPickerData(mViewModel.taskNatureData)
                popup.setCommonPickerListener { _, data ->
                    mBinding.sbNatureTask.rightText = data
                }
                XPopup.Builder(this)
                    .borderRadius(42f)
                    .isDarkTheme(false)
                    .asCustom(popup)
                    .show()
            }
            //现场负责人
            R.id.iv_principal -> {
                if (mViewModel.taskContactData.size == 0) {
                    ToastUtils.showShort("未获取到数据")
                    return
                }
                val popup = CustomCommonPicket(this, getString(R.string.txt_choose_principal))
                popup.setPickerData(mViewModel.taskContactData)
                popup.setCommonPickerListener { position, data ->
                    mBinding.etPrincipal.setText(data)
                    mBinding.etPrincipalPhone.setText(mViewModel.taskContactPhoneData[position])
                }
                XPopup.Builder(this)
                    .borderRadius(42f)
                    .isDarkTheme(false)
                    .asCustom(popup)
                    .show()
            }
            R.id.sb_start_time -> {
                CardDatePickerDialog.builder(this)
                    .setTouchHideable(true)
                    .showBackNow(false)
                    .setMinTime(System.currentTimeMillis())
                    .showFocusDateInfo(false)
                    .setWrapSelectorWheel(false)
                    .setTitle("选择开始时间")
                    .showDateLabel(true)
                    .setBackGroundModel(CardDatePickerDialog.STACK)
                    .setDisplayType(
                        DateTimeConfig.YEAR,
                        DateTimeConfig.MONTH,
                        DateTimeConfig.DAY,
                        DateTimeConfig.HOUR,
                        DateTimeConfig.MIN
                    )
                    .setLabelText("年", "月")
                    .setOnChoose("选择") {
                        startTime = AndroidUtil.conversionTime(it, "yyyy-MM-dd HH:mm")
                        mBinding.sbStartTime.rightText =
                            AndroidUtil.conversionTime(it, "yyyy-MM-dd HH:mm")
                    }
                    .setOnCancel("关闭") {

                    }
                    .build().show()
            }
            R.id.sb_end_time -> {
                CardDatePickerDialog.builder(this)
                    .setTouchHideable(true)
                    .showBackNow(false)
                    .setMinTime(System.currentTimeMillis())
                    .showFocusDateInfo(false)
                    .setWrapSelectorWheel(false)
                    .setTitle("选择结束时间")
                    .showDateLabel(true)
                    .setBackGroundModel(CardDatePickerDialog.STACK)
                    .setDisplayType(
                        DateTimeConfig.YEAR,
                        DateTimeConfig.MONTH,
                        DateTimeConfig.DAY,
                        DateTimeConfig.HOUR,
                        DateTimeConfig.MIN
                    )
                    .setLabelText("年", "月")
                    .setOnChoose("选择") {
                        endTime = AndroidUtil.conversionTime(it, "yyyy-MM-dd HH:mm")
                        mBinding.sbEndTime.rightText =
                            AndroidUtil.conversionTime(it, "yyyy-MM-dd HH:mm")
                    }
                    .setOnCancel("关闭") {
                        ARouter.getInstance().build(RoutePath.Mine.RELEASE_RESULT).navigation()
                        finish()
                    }
                    .build().show()
            }
            R.id.sb_location -> {
                // 申请权限
                PermissionHelper.requestTip(this,"添加地址需要授权定位权限",object :
                    PermissionUtils.SimpleCallback{
                    override fun onGranted() {
                        RouteManager.Main.intentToSearchLocation()

                    }

                    override fun onDenied() {
                        ToastUtils.showShort("请授权后再继续操作")
                    }
                },Manifest.permission.ACCESS_FINE_LOCATION,
                    Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS)

//                PermissionX.init(this)
//                    .permissions(
//                        Manifest.permission.ACCESS_FINE_LOCATION,
//                        Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS,
//                    )
//                    .onExplainRequestReason { scope, deniedList ->
//                        scope.showRequestReasonDialog(
//                            deniedList,
//                            "核心基础功能基于这些权限,请允许,否则影响app正常使用",
//                            "确认",
//                            "取消"
//                        )
//                    }
//                    .onForwardToSettings { scope, deniedList ->
//                        scope.showForwardToSettingsDialog(
//                            deniedList,
//                            "您需要手动在“设置”中允许必要的权限",
//                            "确定",
//                            "取消"
//                        )
//                    }
//                    .request { allGranted, grantedList, deniedList ->
//                        if (allGranted) {
//                            RouteManager.Main.intentToSearchLocation()
//                        } else {
//                            Toast.makeText(
//                                this,
//                                "这些权限被拒绝,可能影响管建宝正常使用" + ": $deniedList",
//                                Toast.LENGTH_LONG
//                            ).show()
//                        }
//                    }

            }
            R.id.tv_commit -> {
                taskTypeList.clear()
                taskConditionList.clear()
                //获取选中任务类型
                for (i in mAdapter!!.multiSelectedPosition) {
                    mViewModel.taskTypeData?.get(i)?.let { taskTypeList.add(it) }
                }
                //添加任务类型其他情况
                if (!TextUtils.isEmpty(mBinding.etTaskType.text.toString())) {
                    taskTypeList.add(mBinding.etTaskType.text.toString())
                }
                //获取选中现场情况类型
                for (i in mAdapterCondition!!.multiSelectedPosition) {
                    mViewModel.taskConditionData?.get(i)?.let { taskConditionList.add(it) }
                }
                //添加任务现场其他情况
                if (!TextUtils.isEmpty(mBinding.etPreliminarySurvey.text.toString())) {
                    taskConditionList.add(mBinding.etPreliminarySurvey.text.toString())
                }
                if (AndroidUtil.isFastClick()) {
                    AndroidUtil.listToString(taskTypeList)?.let {
                        AndroidUtil.listToString(taskConditionList)?.let { it1 ->
                            mViewModel.getTaskAdd(
                                mBinding.sbTitle.rightText.toString(),
                                mBinding.etDesc.text.toString(),
                                mBinding.etName.text.toString(),
                                mBinding.etWorkload.text.toString(),
                                mBinding.sbMeasurementUnit.rightText.toString(),
                                longitude, latitude, addressDetail,
                                mBinding.sbNatureTask.rightText.toString(),
                                startTime,
                                endTime,
                                mBinding.etPrincipal.text.toString(),
                                mBinding.etPrincipalPhone.text.toString(),
                                it,
                                it1,
                                AndroidUtil.listToString(mBinding.imageUploadExplorationPhotos.imagePath)
                                    .toString(),
                                AndroidUtil.listToString(mBinding.imageUploadConstructionDrawings.imagePath)
                                    .toString(),
                                AndroidUtil.listToString(mBinding.imageUploadApprovalProcedures.imagePath)
                                    .toString()
                            )
                        }
                    }
                }
            }
        }
    }


    private fun refreshRongGroupInfo(friendList: List<RongGroupVO>) {
        //融云IM -> 刷新群组信息
        for (i in friendList.indices) {
            //后台拿到的联系人列表id 比对 融云id相同则缓存
            val group = io.rong.imlib.model.Group(
                friendList[i].id,
                friendList[i].name,
                Uri.parse("")
            )

            //通过网络请求动态加载群信息
            RongIM.getInstance().refreshGroupInfoCache(group)
            Logs.d("re缓存群聊信息成功：" + group)
            ARouter.getInstance().build(RoutePath.Mine.RELEASE_RESULT).navigation()
            finish()
        }
    }
}